import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_chubao/tools/app_colors.dart';
import 'package:flutter_chubao/tools/app_textstyle.dart';
import 'package:flutter_chubao/widgets/app_widget_appbar.dart';
import 'package:flutter_chubao/widgets/app_widget_bg.dart';
import 'package:flutter_chubao/widgets/app_widget_protocol.dart';
import 'package:flutter_chubao/widgets/app_widget_space.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'app_login_logic.dart';
import 'app_login_state.dart';

/// @description:
/// @author
/// @date: 2023-12-13 13:54:00
class AppLoginPage extends StatelessWidget {
  final AppLoginLogic logic = Get.put(AppLoginLogic());
  final AppLoginState state = Get.find<AppLoginLogic>().state;

  AppLoginPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: AppWidgetBg(
            assetImage: 'icon_bg_white',
            color: Colors.white,
            child: SafeArea(
                child: Column(
              children: [
                AppWidgetAppbar(
                  backColor: Colors.transparent,
                  isBack: false,
                ),
                Padding(
                  padding: EdgeInsets.only(top: 29.w, left: 31.w, right: 31.w),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text('欢迎使用厨宝',
                          style: AppTextStyle.getBoldTextStyle(fontSize: 24)),
                      SizedBox(
                        height: 24.w,
                      ),
                      SizedBox(
                        height: 42,
                        child: Row(
                          children: [
                            Text(
                              '+86',
                              style: AppTextStyle.getNormalTextStyle(
                                fontSize: 13,
                              ),
                            ),
                            const SizedBox(
                              width: 6,
                            ),
                            Expanded(
                                child: TextField(
                              controller: state.phoneController,
                              style: AppTextStyle.getNormalTextStyle(
                                fontSize: 15,
                              ),
                              inputFormatters: [
                                FilteringTextInputFormatter.allow(
                                    RegExp('[0-9]')),
                                LengthLimitingTextInputFormatter(11)
                              ],
                              decoration: InputDecoration(
                                hintText: '请输入账号',
                                border: InputBorder.none,
                                hintStyle: AppTextStyle.getNormalTextStyle(
                                    fontSize: 15, color: kColorTextB25),
                              ),
                            ))
                          ],
                        ),
                      ),
                      AppWidgetSpace(),
                      SizedBox(
                        height: 12.w,
                        // child: Icon(Icons.keyboard_arrow_down_sharp),
                      ),
                      SizedBox(
                        height: 42,
                        child: Row(
                          children: [
                            Expanded(
                                child: TextField(
                              obscureText: true,
                              controller: state.codeController,
                              style: AppTextStyle.getNormalTextStyle(
                                fontSize: 15,
                              ),
                              decoration: InputDecoration(
                                hintText: '请输入密码',
                                border: InputBorder.none,
                                hintStyle: AppTextStyle.getNormalTextStyle(
                                    fontSize: 15, color: kColorTextB25),
                              ),
                            )),
                            // GetBuilder<AppLoginLogic>(
                            //   id: 'millisUntilFinished',
                            //   builder: (controller) {
                            //     return GestureDetector(
                            //       behavior: HitTestBehavior.opaque,
                            //       onTap: () {
                            //         if (controller.state.millisUntilFinished <=
                            //             0) {
                            //           logic.sendSms();
                            //         }
                            //       },
                            //       child: SizedBox(
                            //         // height: 50,
                            //         // margin: EdgeInsets.only(top: 27.w),
                            //         // alignment: Alignment.centerLeft,
                            //         child: Text(
                            //           controller.state.millisUntilFinished > 0
                            //               ? '${controller.state.millisUntilFinished}s后重发'
                            //               : '发送验证码',
                            //           style:
                            //               controller.state.millisUntilFinished >
                            //                       0
                            //                   ? AppTextStyle.getNormalTextStyle(
                            //                       fontSize: 13,
                            //                       color: kColorTextB25)
                            //                   : AppTextStyle.getNormalTextStyle(
                            //                       fontSize: 13,
                            //                       color: kColorAssistB6),
                            //           // text14C282765
                            //         ),
                            //       ),
                            //     );
                            //   },
                            // )
                          ],
                        ),
                      ),
                      AppWidgetSpace(),
                      Padding(
                        padding: EdgeInsets.only(top: 31.w),
                        child: ElevatedButton(
                            onPressed: () {
                              logic.clickLogin();
                            },
                            child: const Text('登录/注册')),
                      ),
                      SizedBox(
                        height: 15.w,
                      ),
                      AppWidgetProtocol(
                        // protocolName: 'login',
                        // organsIdArr: const ['login', 'register'],
                        clickProtocl: (p0) {
                          state.isAgree = p0;
                        },
                      ),
                    ],
                  ),
                ),
              ],
            ))));
  }
}
